Add overrideable identifier preparation methods#124
Add overrideable identifier preparation methods#124ClaireNeveu wants to merge 3 commits intodatavjs:masterfrom
Conversation
| } | ||
|
|
||
| function prepareTableIdentifier(table, opts) { | ||
| return prepareColumnIdentifier(expandAlias(table), opts); |
There was a problem hiding this comment.
This intentionally points to prepareColumnIdentifier rather than sql._prepareColumnIdentifier so that changing the column escaping behavior doesn't incidentally change the table escaping behavior.
|
Thanks for contributing this, @ClaireNeveu! I'll have to make some time to look at it in more detail. One thing I noticed is that it seems to allow SQL functions to be used directly, where column names are expected -- I think sql-bricks previously required them to be wrapped in The rewrite does seem to be a long way off, as I haven't had much need or motivation to work on it and my attention has been consumed with other projects. An interim solution like this does seem like a good idea. |
|
Sql bricks currently allows you to do In my library I actually add an extra layer requiring you to do |
I'm using sql-bricks in my library and I'd like to add support for automatically converting between snake_case and camelCase.
I've added two overrideable methods on
sql:sql._prepareTableIdentifierandsql._prepareColumnIdentifier. By overriding these you can change the behavior of the auto-quoter or simply hook into that pipeline and then pass the identifier on. This is a global mutation which isn't ideal but it's the best we can do with the current state of sql-bricks.I know there's rumblings about a rewrite that would make it easier to override via inheritance, but since that is a way off I think this would be an acceptable interim solution.
Matching issue: #101